package com.fortune.conf;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

public class ChromeDriverUtil {

    // 获取 WebDriver 实例
    public WebDriver getWebDriver() {
        ChromeOptions options = new ChromeOptions();
        String driverPath = getDriverPath(options);
        System.setProperty("webdriver.chrome.driver", driverPath);
        // 添加必要的启动参数
        options.addArguments("--headless=new");
        options.addArguments("--remote-allow-origins=*");
        options.addArguments("--no-sandbox");
        options.addArguments("--disable-extensions");
        options.addArguments("--disable-gpu");
        options.addArguments("--disable-dev-shm-usage");
        // 根据需要添加其他参数
        WebDriver driver = new ChromeDriver(options);
        // 设置最长等待时间
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        return driver;
    }

    // 获取 chromedriver.exe 的路径
    public static String getDriverPath(ChromeOptions options) {
        // 请替换为实际的 chromedriver.exe 路径
//        return "E:/chromedriver-win64-135.95/chromedriver-win64/chromedriver.exe";
//        return "D:/wwb/packages/chromedriver-win64-135.95/chromedriver-win64/chromedriver.exe";
        return "D:/wwb/packages/chromedriver-win64137.0.7151.69/chromedriver-win64/chromedriver.exe";
//        return "D:/wwb/packages/chromedriver-win64137.70/chromedriver-win64/chromedriver.exe";
    }
}
